Import necessary modules¶
In [1]:
from pathlib import Path
from ipyniivue import download_dataset
BASE_API_URL = "https://niivue.com/demos/images/"
DATA_FOLDER = Path("images")
# Download data for example
download_dataset(
BASE_API_URL,
dest_folder=DATA_FOLDER,
files=[
"complex.nii.gz",
],
)
Downloading complex.nii.gz... Dataset downloaded successfully to images.
In [2]:
import ipywidgets as widgets
from IPython.display import display
from ipyniivue import NiiVue
# Setup NiiVue instance
nv = NiiVue()
intensity_output = widgets.HTML(" ")
@nv.on_location_change
def handle_intensity_change(location):
"""Handle location change."""
intensity_output.value = location["string"]
nv.load_volumes(
[
{"path": DATA_FOLDER / "complex.nii.gz"},
]
)
# Create other widget
slice_type_dropdown = widgets.Dropdown(
options=[
("Axial", 0),
("Coronal", 1),
("Sagittal", 2),
("Render", 4),
("A+C+S+R", 3),
],
value=3,
description="Slice Type:",
)
def on_slice_type_change(change):
"""Set slice type."""
nv.set_slice_type(change["new"])
slice_type_dropdown.observe(on_slice_type_change, names="value")
# Display all
display(widgets.VBox([slice_type_dropdown, nv, intensity_output]))